package cn.ilikes.tools.hbase.jpa;

import org.slf4j.Logger;

import cn.ilikes.tools.hbase.jpa.proxys.LazyInitializerFactory;
import cn.ilikes.tools.hbase.jpa.proxys.cglibs.CglibLazyInitializerFactory;
import cn.ilikes.tools.logs.Loggerfactory;

/**
 * JPA HBase 全局变量
 * 
 * @author fack
 * 
 */
public class JPAHbaseSystemEnv {

	private static Logger logger = Loggerfactory.instance(JPAHbaseSystemEnv.class);

	private static boolean issysinit = false;

	private static JPAHbaseSystemEnv hbaseSystemEnv = new JPAHbaseSystemEnv();

	// cglib lazy
	private LazyInitializerFactory lazyInitializerFactory = new CglibLazyInitializerFactory();

	private void checkInit() {
		if (!issysinit)
			throw new JPAHBaseRuntimeException("JPA Hbase System env  not init !  please init  run  initSystemEnv() ");
	}

	public void initSystemEnv() {
		synchronized (hbaseSystemEnv) {
			if (issysinit) {
				return;
			}
			Loggerfactory.info(logger, "Start Init  JPA Hbase System env init ......");
			issysinit = true;
		}
	}

	public static JPAHbaseSystemEnv getHbaseSystemEnv() {
		return hbaseSystemEnv;
	}

	public LazyInitializerFactory getLazyInitializerFactory() {
		checkInit();
		return lazyInitializerFactory;
	}

}
